#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct LinkNode{
	int data;
	struct LinkNode *next;
}*LinkNode,Node;
typedef struct{
	LinkNode front;
	LinkNode rear;
}LinkQueue;
void QueueInit(LinkQueue **Q){
	(*Q) = (LinkQueue*) malloc(sizeof(LinkQueue));
	(*Q)->front = NULL;
	(*Q)->rear = NULL;
}
bool IsEmpty(LinkQueue *Q){
	if(Q->front == NULL && Q->rear == NULL){
		return true;
	}
	return false;
}
void EnQueue(LinkQueue *Q,int data){
	LinkNode node = (LinkNode) malloc(sizeof(Node));
	node->data = data;
	if(IsEmpty(Q)){
		//说明这是第一个元素
		Q->rear = node;
		Q->front = node;
		return;
	}
	Q->rear->next = node;
	Q->rear = node;
}
void DeQueue(LinkQueue *Q,int *data){
	if(IsEmpty(Q)){
		printf("队列已空！\n");
		return;
	}
	*data = Q->front->data;
	LinkNode temp = Q->front;
	if(Q->front == Q->rear){
		//假如只剩一个元素
		Q->front  = NULL;
		Q->rear  = NULL;
		free(temp);
		return;
	}
	Q->front = temp->next;
	free(temp);
}
void QueueOutPut(LinkQueue *Q){
	LinkNode temp = Q->front;
	while (temp) {
		printf("%d\n",temp->data);
		temp = temp->next;
	}
}
int main(int argc, char *argv[]) {
	int data,choose;
	LinkQueue *Q;
	QueueInit(&Q);
	while (1) {
		printf("1.入队 2.出队 3.输出队列\n");
		printf("请输入你的选择:");
		scanf("%d",&choose);
		if(choose == 1){
			int a;
			printf("请输入你要入队的数据:");
			scanf("%d",&a);
			EnQueue(Q, a);
		}
		else if (choose == 2) {
			DeQueue(Q, &data);
			printf("%d\n",data);
		}
		else if (choose == 3) {
			QueueOutPut(Q);
		}
	}
}